﻿package blob.characters
{
    import org.flixel.*;

    public class SmallCharacter extends Character
    {
        private var blobSmallImg:Class;
        private var noMerge:int;
        private var walking:int;

        public function SmallCharacter(param1:Number, param2:Number)
        {
            this.blobSmallImg = SmallCharacter_blobSmallImg;
            super(param1, param2);
            loadGraphic(this.blobSmallImg, true, true, 41, 40);
            width = 29;
            offset.x = 6;
            addAnimation("walk", [1, 2, 3, 4], 8, true);
            addAnimation("idle", [0, 9], 4, true);
            addAnimation("jump", [3, 5], 6, false);
            addAnimation("noMerge", [8, 7], 3, true);
            _moveSpeed = 300;
            _jumpPower = 500;
            this.noMerge = 0;
            this.walking = 0;
            return;
        }// end function

        override public function merge(param1:Character) : Character
        {
            var _loc_2:Character = null;
            if (param1.height > this.height)
            {
                _loc_2 = new LargeCharacter(x, y);
            }
            else
            {
                _loc_2 = new MediumCharacter(x, y);
            }
            _loc_2.x = x - width - 5;
            _loc_2.y = this.y + this.height - _loc_2.height;
            if (isOverlapping(_loc_2))
            {
                _loc_2.x = x;
                if (isOverlapping(_loc_2))
                {
                    _loc_2.y = y + height;
                    if (isOverlapping(_loc_2))
                    {
                        _loc_2.kill();
                        this.setCouldntMerge();
                        param1.setCouldntMerge();
                        return null;
                    }
                }
            }
            param1.kill();
            this.kill();
            return _loc_2;
        }// end function

        override public function split() : Array
        {
            var _loc_1:* = new Array();
            _loc_1.push(this);
            return _loc_1;
        }// end function

        override public function setCouldntMerge() : void
        {
            this.noMerge = 80;
            return;
        }// end function

        override public function update() : void
        {
            if (velocity.x == 0)
            {
                this.walking = 0;
            }
            if (this.noMerge > 0)
            {
                play("noMerge");
                var _loc_1:String = this;
                var _loc_2:* = this.noMerge - 1;
                _loc_1.noMerge = _loc_2;
            }
            else if (velocity.x != 0 && isTouching(FlxObject.DOWN))
            {
                play("walk");
            }
            else if (!isTouching(FlxObject.DOWN))
            {
                play("jump");
            }
            else
            {
                play("idle");
            }
            super.update();
            return;
        }// end function

    }
}
